/*    */ package com.newcrm.config;
/*    */ 
/*    */ import com.newcrm.bean.Province;
/*    */ import java.io.PrintStream;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import org.apache.commons.configuration.Configuration;
/*    */ import org.apache.commons.configuration.ConfigurationException;
/*    */ import org.apache.commons.configuration.PropertiesConfiguration;
/*    */ 
/*    */ public class ProvinceReader
/*    */ {
/* 14 */   private static ProvinceReader reader = null;
/*    */ 
/* 16 */   private List<Province> provinces = new ArrayList();
/*    */ 
/*    */   private ProvinceReader() {
/*    */     try {
/* 20 */       Configuration config = new PropertiesConfiguration(
/* 21 */         "city.properties");
/* 22 */       Iterator it = config.getKeys();
/* 23 */       while (it.hasNext()) {
/* 24 */         String key = (String)it.next();
/* 25 */         if ((key != null) && (key.trim().length() > 0)) {
/* 26 */           Province province = new Province();
/* 27 */           province.name = key;
/* 28 */           String value = config.getString(key);
/* 29 */           if ((value != null) && (value.trim().length() > 0)) {
/* 30 */             province.citys = value.split("_");
/*    */           }
/* 32 */           this.provinces.add(province);
/*    */         }
/*    */       }
/*    */     } catch (ConfigurationException e1) {
/* 36 */       e1.printStackTrace();
/*    */     }
/*    */   }
/*    */ 
/*    */   public static ProvinceReader getInstance()
/*    */   {
/* 42 */     if (reader == null) {
/* 43 */       reader = new ProvinceReader();
/*    */     }
/* 45 */     return reader;
/*    */   }
/*    */ 
/*    */   public List<Province> read() {
/* 49 */     return this.provinces;
/*    */   }
/*    */ 
/*    */   public String[] getProvinceInfo(String address) {
/* 53 */     if ((address == null) || (address.trim().length() == 0)) {
/* 54 */       return null;
/*    */     }
/* 56 */     if (this.provinces.size() == 0) {
/* 57 */       return null;
/*    */     }
/* 59 */     String[] info = new String[2];
/* 60 */     for (Province province : this.provinces) {
/* 61 */       if (address.contains(province.name)) {
/* 62 */         info[0] = province.name;
/* 63 */         if ((province.citys != null) && (province.citys.length > 0)) {
/* 64 */           for (String city : province.citys) {
/* 65 */             if (address.contains(city)) {
/* 66 */               info[1] = city;
/* 67 */               return info;
/*    */             }
/*    */           }
/*    */         }
/* 71 */         return info;
/*    */       }
/*    */     }
/* 74 */     return null;
/*    */   }
/*    */ 
/*    */   public static void main(String[] args)
/*    */ {
/* 81 */
    ProvinceReader reader = getInstance();
/* 82 */
    List provinces = reader.read();
/* 83 */
    int idx = 1;
    for (Object provinceO : provinces) {
        Province province = (Province) provinceO;
/*    */
        {
/* 86 */
            System.out.println("province[" + idx + "] = {name:'" +
/* 87 */         province.name + "', citys:[" + province.getCitys() + 
/* 88 */         "]};");
/*    */ 
/* 90 */
            idx++;
/*    */
        }
/*    */
    }
}
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.config.ProvinceReader
 * JD-Core Version:    0.6.1
 */